package dao.impl;

import dao.IGoodsDao;
import model.Goods;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @aythor:侯仪澳
 * @data:2022/7/21
 */
@Repository
public class GoodsDao implements IGoodsDao {
    @Autowired
    private SqlSession sqlSession;
    String url = "dao.IGoodsDao.";

    //查询所有商品
    @Override
    public List<Goods> queryAllGoods(Goods goods) {
        return sqlSession.selectList(url + "queryAllGoods",goods);
    }

    //根据状态值查询所有订单   1-上架  0-下架
    @Override
    public List<Goods> queryGoodsByStatus(Map<String, Object> map) {
        return sqlSession.selectList(url + "queryGoodsByStatus",map);
    }

    //添加商品
    @Override
    public int addOneGoods(Goods goods) {
        return sqlSession.insert(url + "addOneGoods",goods);
    }

    //修改上架下架状态值
    @Override
    public int updateGoodsBatch(List<Goods> list) {
        return sqlSession.update(url + "updateGoodsBatch",list);
    }

    //一级分类
    @Override
    public List<Goods> queryFirstSort(Goods goods) {
        return sqlSession.selectList(url + "queryFirstSort",goods);
    }

    //二级分类
    @Override
    public List<Goods> querySecondSort(Goods goods) {
        return sqlSession.selectList(url + "querySecondSort",goods);
    }

    //修改货物信息
    @Override
    public int updateOneGoods(Goods goods) {
        return sqlSession.update(url + "updateOneGoods",goods);
    }

    //扣减库存
    @Override
    public int subCount(Map<String,Integer> map) {
        return sqlSession.update(url + "subCount",map);
    }

    @Override
    public int addGoodsCount(Goods goods) {
        return sqlSession.update(url + "addGoodsCount",goods);
    }

}
